<template>
  <div class="app-container">
    毒株设置列表

    <el-table
      :data="this.list" stripe style="width: 100%">
      <el-table-column type="index" width="50" label="序号"/>
      <el-table-column prop="point" label="省"/>
      <el-table-column prop="category" label="毒株种类" :formatter="formatData"/>
      <el-table-column prop="note" label="备注" width="200"/>
      <el-table-column label="操作" width="280" align="center">
        <template slot-scope="scope">
          <el-button type="danger" size="mini"
                     icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除</el-button>
          <router-link :to="'/virus/edit/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit"></el-button>
          </router-link>

        </template>
      </el-table-column>

    </el-table>
    <router-link :to="'/virus/add/'">
    <el-button type="primary" icon="el-icon-circle-plus">新增</el-button>
    </router-link>
    <!-- 分页 -->
    <el-pagination
      :current-page="current"
      :page-size="limit"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getList"
    />
  </div>
</template>

<script>
import virus from '@/api/virus'
export default{
  data(){
    return{
      current:1, //当前页
      limit:3, //每页显示记录数
      searchObj:{}, //条件封装对象
      list:[], //每页数据集合
      total:0,//总记录数
    }
  },
  created() {
    this.getList()
    console.log(this.list)
  },
  methods:{
    getList(){//添加当前页参数
      virus.getviruslist()
        .then(response=>{//接口返回数据
          //返回集合list
          this.list = response.data
          console.log(this.list)
        })//请求成功
        .catch(error=>{//请求失败
          console.log(error)
        })
    },
    removeDataById(id){
      this.$confirm('此操作将永久删除设置信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {virus.deleteInfo(id).then(response=>{
        //提示信息
        this.$message({

          type: 'success',
          message: '删除成功!'
        })
        this.getList()
      })
      })
    },
    formatData(row) {
      let rowPerson = (row && row.category) || [];
      let arr = [];
      rowPerson.forEach(item => {
        //如果数据特别多的话,还可以在这里加if判断,仅展示规定的数据
        arr.push(item);
      });
      //
      return arr.join(";");
    }
  }
}
</script>
